package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AddNursingLeverDto;
import com.zzyl.dto.GetPageNursingsDto;
import com.zzyl.dto.UpdateNursingLeverDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 查询全部
     * @return
     */
    @GetMapping("/listAll")
    @ApiOperation(value = "查询全部")
    public ResponseResult getAllNursingLevel(){
      List<NursingLevelVo> nursingLevelList=  nursingLevelService.getAllNursingLevel();
      return ResponseResult.success(nursingLevelList);
    }

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/listByPage")
    @ApiOperation(value = "分页查询")
    public ResponseResult getPageNursingLevel(GetPageNursingsDto dto ){
       PageResponse pageResponse= nursingLevelService.getPageNursingLevel(dto);

       return ResponseResult.success(pageResponse);
    }

    /**
     * 根据id查
     * @return
     */
    @GetMapping("{id}")
    @ApiOperation(value = "根据id查")
    public ResponseResult getNursingLevelById(@PathVariable Integer id){
      NursingLevelVo nursingLevelVo= nursingLevelService.getNursingLevelById(id);
      return ResponseResult.success(nursingLevelVo);
    }

    /**
     * 删除等级
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除等级")
    public ResponseResult deleteNursingLevelById(@PathVariable Integer id){
        nursingLevelService.deleteNursingLevelById(id);
             return ResponseResult.success();
    }

    /**
     * 新增等级
     * @param dto
     * @return
     */
    @PostMapping("/insert")
    @ApiOperation(value = "新增等级")
    public ResponseResult insertNursingLevel(@RequestBody AddNursingLeverDto dto){
        nursingLevelService.insertNursingLevel(dto);
        return ResponseResult.success();
    }

    /**
     * 修改等级
     * @param dto
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改等级")
    public ResponseResult updateNursingLevel(@RequestBody UpdateNursingLeverDto dto){
        nursingLevelService.updateNursingLever(dto);
        return ResponseResult.success();
    }

    /**
     * 启用禁用
     * @param id
     * @param status
     * @return
     */
    @PutMapping("{id}/status/{status}")
    @ApiOperation(value = "启用禁用")
    public ResponseResult updateNursingLevel(@PathVariable("id")Integer id,@PathVariable("status")Integer status){
        nursingLevelService.updateNursingLevel(id,status);
        return ResponseResult.success();
    }
}
